﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//for htf
using WodLib.Tools;
//for editor
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace WodLib.Controls
{
    public class WodCollectionEditor<T> : UITypeEditor
        where T:WodObject
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }
           
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (!(value is List<T>))
                return value;
            
            IWindowsFormsEditorService service = (IWindowsFormsEditorService)
                provider.GetService(typeof(IWindowsFormsEditorService));

            if (service != null)
            {
                WodCollectionEditorForm<T> editor = 
                    new WodCollectionEditorForm<T>((List<T>)value);
                service.ShowDialog(editor);
            }

            return value;
        }
    }
}
